<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: install.php 2010-09-07 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Like
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Like_Installer extends Engine_Package_Installer_Module
{
  function onPreInstall()
  {
    $db = $this->getDb();
    $select = new Zend_Db_Select($db);

    $select
      ->from('engine4_core_modules')
      ->where('name = ?', 'hecore')
      ->where('enabled', 1)
      ->limit(1);

    $module_exists = $select->query()->rowCount();

    if (!$module_exists) {
      return $this->_error('Error! This plugin requires Hire-Experts Core module. It is free module and can be downloaded from Hire-Experts.com');
    }
	
	$select = new Zend_Db_Select($db);
	
	$db->insert("engine4_hecore_modules", array("name" => "like", "version" => "4.0.1", "key" => "xxxxxxxxxxxxxxx", "installed" => 1, ));
    
    $select
      ->from('engine4_hecore_modules')
      ->where('name = ?', 'like', 'STRING')
      ->where('installed = ?', 1, 'INTEGER')
      ->limit(1);
    
    $module_installed = $select->query()->rowCount();

    if (!$module_installed){
      $urlParams = array(
        'module' => 'hecore',
        'controller' => 'module',
        'action' => 'license',
        'name' => 'like',
        'version' => '4.0.1',
        'format' => 'smoothbox'
      );

      $front = Zend_Controller_Front::getInstance();
      $register_url = str_replace('install/', '', $front->getRouter()->assemble($urlParams, 'default', true));

      $error_message = Zend_Registry::get('Zend_Translate')
        ->_('It is paid plugin from Hire-Experts LLC. You need to type License Key to install this module - <a class="smoothbox" href="%s">Click Here</a>');

      $error_message = sprintf($error_message, $register_url);

      return $this->_error($error_message);
    }

    parent::onPreInstall();
  }

    function onInstall()
  {
    parent::onInstall();
  }

  protected function checkModule($module)
  {
      $db = $this->getDb();

    $select = new Zend_Db_Select($db);
    $select
      ->from('engine4_core_modules')
      ->where('name = ?', $module)
      ->where('enabled = 1');

    $info = $select->query()->fetch();

    return (!empty($info));
  }


}